<template>
	<view class="route-coupon">
		<view class="inner">
			<u-sticky bgColor="#fff">
				<u-tabs :current="currentActive" lineColor="#ED2920" :list="tabList" @change="handleChageTab"></u-tabs>
			</u-sticky>
			<view style="width:100%;height:40rpx"></view>
			<view class="have" v-if="couponList.length">
				<view class="coupon-item " v-for="(item,index) in couponList" :key="index">
					<view class="item-info">
						<view class="bgcoupon">
							<image class="img" src="../../static/images/couponBlue.png" mode=""></image>
						</view>
						<view class="info-inner">
							<view class=" left-box">
								<view class="coupon-num-box">{{item.price}} <text>元</text> </view>
								<view class="coupon-rule">满{{item.fullprice}}元使用</view>
							</view>
							<view class="middle">
								<view class="top">
									<view class="coupon-title">{{item.name}}</view>
								</view>
								<view class="desc">
									{{item.title}}
								</view>
								<view class="dqsj">
									到期时间：{{timeForMat(item.endtime)}}
								</view>

							</view>
							<view class="right">
								<!-- <view class="btn">
										去使用
									</view> -->
								<!-- <view class="btn editbtn">
										编辑
									</view>
									<view class="btn">
										上架
									</view> -->
							</view>

						</view>
						<!-- <view class="disimg">
								<image class="img-cont" src="../../static/images/coupon-gq.png" mode=""></image>
							</view> -->
					</view>

					<view class="">

					</view>
				</view>
			</view>
			<view class="none" v-else>
				<u-empty mode="list">
				</u-empty>
			</view>

		</view>

	</view>
</template>

<script setup>
	import dayjs from 'dayjs'
	import {
		couponApi
	} from '@/api/index.js'
	import handleCache from "@/utils/cache.js"
	import {
		ref,
		computed
	} from 'vue'
	import {
		onShow
	} from "@dcloudio/uni-app"
	const currentActive = ref(0)
	const tabList = ref([{
			name: '待使用'
		},
		{
			name: '已使用'
		}
	])
	const userInfo = ref('')
	const couponList = ref([])
	onShow(() => {
		userInfo.value = handleCache.get('userInfo')
		getMyCoupon()
	})
	let timeForMat = computed(() => {
		return function(val) {
			console.log(val, 8888)
			return dayjs.unix(val).format('YYYY-MM-DD HH:mm:ss')
		}
	})
	const handleChageTab = (data) => {
		let index = data.index
		currentActive.value = index
		couponList.value = []
		getMyCoupon()
	}
	const getMyCoupon = () => {
		let req = {
			uid: userInfo.value.id,
			shanghuid: userInfo.value.shanghuid,
			status: currentActive.value + 1
		}
		couponApi.couponuser(req, {
			loading: {
				text: '加载中'
			}
		}).then((res) => {
			couponList.value = res.data || []
		})
	}
</script>

<style lang="scss" scoped>
	@import 'index.scss'
</style>